package com.itrencai.d1_static.demoYZM;

import java.util.Random;

public class VerifyTool {
    //私有构造器,不对外产生对象，节约内存
    private VerifyTool() {
    }

    //静态方法用于封装验证码
    public static String createCode(int n){
        //验证码
        //1.使用String开发一个验证码
        String chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        //定义一个变量用于存储5位随机的字符作为验证码
        String code="";
        //3.循环
        Random r=new Random();
        for (int i = 0; i < n; i++) {
            int index=r.nextInt(chars.length());
            //对应索引提取字符
            code+=chars.charAt(index);
        }
        //System.out.println("验证码："+code);
        return code;
    }
}
